package com.dcy.factory.absfactory.pizzastore.order;

import com.dcy.factory.absfactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/1/20 15:01
 */
public class OrderPizza {

    AbsFactory absFactory;

    public OrderPizza(AbsFactory absFactory) {
        this.absFactory = absFactory;
        Pizza pizza;
        // 订购披萨的类型
        String orderType;
        do {
            orderType = getType();
            // factory 可能是北京的工厂子类，也可能是伦敦的工厂类
            pizza = this.absFactory.createPizza(orderType);
            // 输出pizza 制作过程
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败");
                break;
            }
        } while (true);
    }

    /**
     * 写一个方法，可以获取客户希望订购的披萨种类
     *
     * @return
     */
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza种类:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
